WIT_BASE = $(abspath ./libwwt/wiimms-iso-tools/project)

# TODO split into multiple lines
INCLUDE_DIRS = "$(WIT_BASE)/:$(WIT_BASE)/src/:$(WIT_BASE)/src/libwbfs/:$(WIT_BASE)/src/crypto/:$(WIT_BASE)/dclib/:./libwwt/:/usr/include/:/usr/local/include/"

ifeq ($(PREFIX),)
	PREFIX := usr/
endif


# Build shared lib from wwt
.PHONY : bundle
bundle:
	# Clone libwwt as needed
	if [ ! -d "./libwwt" ]; then \
		git clone --recurse-submodules "https://notabug.org/CYBERDEViL/libwwt"; \
	fi
	# Build libwwt
	@cd libwwt && $(MAKE) shared
	# Build pywwt
	@python3 setup.py build_ext --include-dirs="$(INCLUDE_DIRS)" --library-dirs="./libwwt/bin/shared/"


.PHONY : install
install:
	# Install libwwt
	@PREFIX="$(PREFIX)" DESTDIR="${DESTDIR}" $(MAKE) -C ./libwwt/ install
	# Install pywwt
	@python3 setup.py install --root="$(DESTDIR)" --optimize=1 --skip-build
